#ifndef __TERMINAL_H_
#define __TERMINAL_H_

/*Console colors without style and bgcolor*/
#if defined(TERMINAL_COLOR)
#include <stdio.h>
#define _BLACK		 "\033[0;30m"
#define _RED  		 "\033[0;31m"
#define _GREEN 		 "\033[0;32m"
#define _YELLOW		 "\033[0;33m"
#define _BLUE  		 "\033[0;34m"
#define _PURPLE		 "\033[0;35m"
#define _SKY		 "\033[0;36m"
#define _WHITE		 "\033[0;37m"
#define _END_COLOR	 "\033[0m"
/*Console styles*/
#define _CLOSE		 "\033[0m"
#define _HIGHLIGHT	 "\033[1m"
#define _UNDERLINE 	 "\033[4m"
#define _BLINK		 "\033[5m"
#define _REVERSE	 "\033[7m"
#define _FADEOUT	 "\033[8m"

#define _PCOLOR(color) do{ if (isatty(0)) fprintf(stdout,"%s",color);}while(0)
/*Console cursor actions*/
#define CURSOR_UP(x) 		do{ if (isatty(0)) fprintf(stdout,"\033[%dA",(x));fflush(stdout);} while(0)
#define CURSOR_DOWN(x) 		do{ if (isatty(0)) fprintf(stdout,"\033[%dB",(x));fflush(stdout);} while(0)
#define CURSOR_RIGHT(x) 	do{ if (isatty(0)) fprintf(stdout,"\033[%dC",(x));fflush(stdout);} while(0)
#define CURSOR_LEFT(x) 		do{ if (isatty(0)) fprintf(stdout,"\033[%dD",(x));fflush(stdout);} while(0)
#define CURSOR_GOTOXY(x,y) 	do{ if (isatty(0)) fprintf(stdout,"\033[%d;%dH",(y),(x));fflush(stdout);} while(0)
#define CURSOR_CLS()		do{ if (isatty(0)) fprintf(stdout,"\033[2J")   ; fflush(stdout); } while(0)
#define CURSOR_STORE()		do{ if (isatty(0)) fprintf(stdout,"\033[s")    ; fflush(stdout);} while(0)
#define CURSOR_RESET()		do{ if (isatty(0)) fprintf(stdout,"\033[u")    ; fflush(stdout);} while(0)
#define CURSOR_DELLINE()	do{ if (isatty(0)) fprintf(stdout,"\033[K")    ; fflush(stdout);} while(0)
#define CURSOR_HIDE()		do{ if (isatty(0)) fprintf(stdout,"\033[?25l") ; fflush(stdout);} while(0)
#define CURSOR_SHOW()		do{ if (isatty(0)) fprintf(stdout,"\033[?25h") ; fflush(stdout);} while(0)

extern int isatty(int);
extern int fprintf(FILE*,const char *, ...);
extern int set_term_mode(int fd);
extern int resume_term_mode(int fd);
extern void set_key(void);
extern void reset_key(void);
#else
#define _BLACK		 
#define _RED  		 
#define _GREEN 		 
#define _YELLOW		 
#define _BLUE  		 
#define _PURPLE		 
#define _SKY		 
#define _WHITE		 
#define _END_COLOR	 
/*Console styles*/
#define _CLOSE		 
#define _HIGHLIGHT	 
#define _UNDERLINE 	 
#define _BLINK		 
#define _REVERSE	 
#define _FADEOUT	

#define _PCOLOR(color) 
/*Console cursor actions*/
#define CURSOR_UP(x) 
#define CURSOR_DOWN(x)
#define CURSOR_RIGHT(x)
#define CURSOR_LEFT(x) 		
#define CURSOR_GOTOXY(x,y) 
#define CURSOR_CLS()	
#define CURSOR_STORE()
#define CURSOR_RESET()
#define CURSOR_DELLINE()
#define CURSOR_HIDE()
#define CURSOR_SHOW()
#endif
#endif
